﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;

namespace HZ.Supervise.Web.Peculiar
{
    public partial class AreaDeleteProcure : BasePage
    {
        DataTable dt = new DataTable();
        int totalrecord = 0;
        public AreaDeleteProcure() 
        {
            this.ModuleNo = "特殊权限";
            this.PageOperateType = "维护";
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            dataBind(); 
        }

        private void dataBind()
        {

            StringBuilder where = new StringBuilder();
            where.Append(" and DAreaid like '%" + CurrentAccount.GetUser().Org.Area.AreaID.TrimEnd('0') + "%'");
            if (!string.IsNullOrEmpty(txtProductName.Text.Trim()))
            {
                //中文按Produtname查询，英文按照PinyinCode查询
                if (HZ.Common.zhHansUtil.HaveChineseCode(this.txtProductName.Text.Trim()))
                {
                    where.Append(" and ProductName like '%" + txtProductName.Text.Trim() + "%'");
                }
                else
                {
                    where.Append(" and PinyinCode like '%" + txtProductName.Text.Trim() + "%'");
                }
            }
            if (!string.IsNullOrEmpty(txtMedicineModelName.Text.Trim()))
            {
                where.Append(" and MedicineModelName = '" + txtMedicineModelName.Text.Trim() + "'");
            }
            if (ddlSortSource.SelectedValue != "-1")
            {
                where.Append(" and SortSource = '" + ddlSortSource.SelectedValue + "'");
            }
            if (!string.IsNullOrEmpty(txtOutlookc.Text.Trim()))
            {
                where.Append(" and Outlookc = like  '%" + txtOutlookc.Text.Trim() + "%'");
            }
            if (!string.IsNullOrEmpty(txtUnit.Text.Trim()))
            {
                where.Append(" and Unit = '" + txtUnit.Text.Trim() + "'");
            }
            if (!string.IsNullOrEmpty(txtCompanyName_SC.Text.Trim()))
            {
                where.Append(" and tCompanyName_SC like '%" + txtCompanyName_SC.Text.Trim() + "%'");
            }
            HZ.Supervise.IBLL.IBLL_SpecialAuthority sp = HZ.Supervise.BLLFactory.IBLL_SpecialAuthority();
            dt = sp.findTAreaDeleteProcure(where.ToString(), AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalrecord);
            gvwProduceCatalog.DataSource = dt;
            gvwProduceCatalog.DataBind();
            AspNetPager1.RecordCount = totalrecord;
        }

        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
            dataBind();
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            dataBind();
        }
        protected void gvwProduceCatalog_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.Equals("View"))
            {

                string[] ids = e.CommandArgument.ToString().Split(',');
                HZ.Web.WebUtil.WriteUserDefinedScript(string.Format("open('Lookhistory.aspx?id2=1&id3={0}&id4={1}');", ids[0], ids[1]), this);

            }
        }
    }
}
